package com.atguigu.oshi;

import org.junit.jupiter.api.Test;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.software.os.OperatingSystem;

import java.util.Arrays;

/**
 * @program: oshi
 * @description:
 * @author: Mr.Yan
 * @create: 2024-12-08 15:56
 **/
public class OshiTest {
//测试获取操作系统信息
    @Test
void test(){
		 SystemInfo si = new SystemInfo();
		 //获取操作系统信息
		 OperatingSystem os = si.getOperatingSystem();
		 System.out.println("操作系统名称：" + os.getFamily());
		 System.out.println("操作系统版本号：" + os.getManufacturer());
		 //获取系统架构信息
		}
		//测试获取内存信息
@Test
		void test2() {
		 SystemInfo si = new SystemInfo();
		 //获取cpu信息
		 CentralProcessor processor = si.getHardware().getProcessor(); //获取CPU
		 System.out.println("CPU型号：" + processor.getProcessorIdentifier().getName()); //获取CPU型号
		 System.out.println("CPU核心数：" + processor.getLogicalProcessorCount()); //获取CPU核心数
		 System.out.println("CPU频率：" + processor.getMaxFreq()); //获取CPU最大频率
 long[] currentFreq = processor.getCurrentFreq();
 System.out.println("CPU当前频率：" + Arrays.toString(currentFreq)); //获取CPU当前频率
 //当前CPU占用率
 System.out.println("CPU占用率：" + Arrays.toString(processor.getProcessorCpuLoad(1000)));
		}




}
